package com.cdlj.moes.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.cdlj.moes.common.Constants;

public class MOESBaseHelper extends SQLiteOpenHelper {

    private static MOESBaseHelper helper;

    private MOESBaseHelper(Context context) {
        super(context, Constants.APP_TAG, null, 1);
    }

    public static MOESBaseHelper getInstance(Context context) {
        if (helper != null) {
            return helper;
        }
        return helper = new MOESBaseHelper(context);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(UserInfoSQLiteHelper.CREATE_TABLE);
//        db.execSQL(CarparkInfoSQLiteHelper.CREATE_TABLE);
//        db.execSQL(CarLocationInfoSQLiteHelper.CREATE_TABLE);
//        db.execSQL(FavoriteInfoSQLiteHelper.CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + UserInfoSQLiteHelper.TBL_MC_APPS_USER);
//        db.execSQL("DROP TABLE IF EXISTS " + CarparkInfoSQLiteHelper.TBL_MC_APPS_USER2CARPARK);
//        db.execSQL("DROP TABLE IF EXISTS " + CarLocationInfoSQLiteHelper.TBL_MC_APPS_CAR_LOCATION);
//        db.execSQL("DROP TABLE IF EXISTS " + FavoriteInfoSQLiteHelper.TBL_MC_APPS_USER2FAVORITE);
        onCreate(db);
    }

}
